<?

// Heeft nog 1 bug :( het heeft te maken met de query die word uitgevoerd maar in mysql doet hij het
// maar dan in php niet meer :'( 

require_once('library/connect.php');
require_once('library/config.php');

$var = @$_POST['search'] ;
$trimmed = trim($var); 
$limit=5; 

if ($trimmed == "")
  {
	  echo "<p>Please enter a search...</p>";
	  exit;
  }

if (!isset($var))
  {
	  echo "<p>We dont seem to have a search parameter!</p>";
	  exit;
  }


$query = "SELECT * FROM p1_movies WHERE p1_movies.movieName LIKE '%".$trimmed."%'";
echo $query;

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);

if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";

// google
 echo "<p><a href=\"http://www.google.com/search?q=" 
  . $trimmed . "\" target=\"_blank\" title=\"Look up 
  " . $trimmed . " on Google\">Click here</a> to try the 
  search on google</p>";
  }

  if (empty($s)) {
  	$s=0;
  }
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");

echo "<p>You searched for: &quot;" . $var . "&quot;</p>";

echo "Results";
$count = 1 + $s ;

while ($row= mysql_fetch_array($result)) {
	$trimmedDescr = $data->movieDesc;
	$trimmedDescr = substr($trimmedDescr,0,150);
	if($data->rating != NULL)$rating=$data->rating;else $rating="N/A";
	$title = $row["movieName"];
	echo $count.')&nbsp;$title.<br/>' ;
	echo '<img src="'.$row["movieImage"].'" width="100px" height="100px"/><br/>';
	echo $trimmedDescr.'<br/>';
	echo '<a href="'.$row["movieFlv"].'">Trailer</a>';
	$count++ ;
}
$currPage = (($s/$limit) + 1);
echo "<br />";
  if ($s>=1) { 
	  $prevs=($s-$limit);
	  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
	  Prev 10</a>&nbsp&nbsp;";
  }
$pages=intval($numrows/$limit);

  if ($numrows%$limit) {
  	$pages++;
  }
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
	  $news=$s+$limit;
	  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
  }
  $a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>"; 

?>